Skip to content

major: build islands + scan routeDir without importing user code#3122

Merged
marvinhagemeister merged 21 commits into
mainfrom
island-builder
Jul 24, 2025
Merged

major: build islands + scan routeDir without importing user code#3122
marvinhagemeister merged 21 commits into
mainfrom
island-builder

Conversation

@marvinhagemeister

@marvinhagemeister marvinhagemeister commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

This fixes a bunch of long standing issues in our tracker where a build wouldn't finish because of importing user code. It's common for backend apps to spawn some open ended tasks like subscribing to Deno KV or other things. This addresses another problem of having to set up ENV vars just for the build, even though they are technically not required to build islands.

This also gives a roughly ~30% performance boost on cold starts (at least on deno.com). Unfortunately, this does require some breaking changes. But I believe the performance improvements + removing the footgun of loading user code during build is well worth it. This work is also a precursor in case we want to exploring moving to vite at some point in the future.

Breaking changes

  1. Build options have moved to the builder.
  // main.ts
- const app = new App({ build: { outDir: "dist/" } })
+ const app = new App()

  // dev.ts
- const builder = new Builder();
+ const builder = new Builder({ outDir: "dist/" });
  1. Another breaking change is how file based routes are loaded. Since they're prepared and loaded by the builder the API changed.
  // main.ts
  const app = new App()
    .use(staticFiles())
  
- await fsRoutes(app, {
-   loadIsland: (path) => import(`./islands/${path}`),
-   loadRoute: (path) => import(`./routes/${path}`),
- }); 
+ app.fsRoutes()

You can optionally change the islandDir or routeDir by passing that to the Builder:

// dev.ts
const builder = new Builder({
  islandDir: "/path/to/islands", 
  routeDir: "/path/to/routes"
});
  1. Import app lazily in dev.ts. Passing app to builder.build() is not necessary anymore.
- import { app } from "./main.ts";

  const builder = new Builder({ target: "safari12" });
  
  if (Deno.args.includes("build")) {
-    await builder.build(app);
+    await builder.build();
  } else {
-   await builder.listen(app);
+   await builder.listen(() => import("./main.ts"));
  }
  1. The production run command has changed. It's now using deno serve
  // deno.json
  {
    "tasks": {
      "dev": "deno run -A --watch=static/,routes/ dev.ts",
      "dev": "deno run -A dev.ts build",
-     "start": "deno run -A main.ts",
+     "start": "deno serve -A _fresh/server.js",
    }
  }

Remove this bit in main.ts:

  // main.ts
  
- if (import.meta.main) {
-   await app.listen()
- }

Fixes #2240
Fixes #2640
Fixes #2592
Fixes #1843

marvinhagemeister and others added 2 commits July 23, 2025 18:03
This fixes a bunch of long standing issues in our tracker where a build
wouldn't finish because of importing user code. It's common for backend
apps to spawn some open ended tasks like subscribing to Deno KV or other
things. This addresses another problem of having to set up ENV vars just
for the build, even though they are technically not required to build
islands.

This also gives a roughly ~30% performance boost on cold starts.
@deno-deploy deno-deploy Bot had a problem deploying to Preview July 23, 2025 16:04 Failure
@deno-deploy deno-deploy Bot had a problem deploying to Preview July 23, 2025 16:09 Failure
@deno-deploy deno-deploy Bot had a problem deploying to Preview July 23, 2025 16:27 Failure
@deno-deploy deno-deploy Bot had a problem deploying to Preview July 23, 2025 16:30 Failure
@deno-deploy deno-deploy Bot had a problem deploying to Preview July 23, 2025 16:33 Failure

@csvn csvn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my unsolicited feedback here on this in-progress PR, but was excited given the interesting and breaking changes. Even if I have vague misgivings about the entrypoint, this PR looks really awesome and promising and well worth the breaking changes! 🎉

Comment thread src/fs_routes.ts Outdated
Comment thread src/config.ts
Comment thread init/src/init.ts Outdated
Comment thread init/src/init.ts
@iuioiua

iuioiua commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

Shall I close #2874?

@deno-deploy deno-deploy Bot had a problem deploying to Preview July 24, 2025 09:04 Failure
@marvinhagemeister marvinhagemeister marked this pull request as ready for review July 24, 2025 10:50
@marvinhagemeister marvinhagemeister merged commit 118242e into main Jul 24, 2025
9 checks passed
@marvinhagemeister marvinhagemeister deleted the island-builder branch July 24, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants